﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TR.AppService.Dto;
using TR.AppService.Dto.SupplyDto;
using TR.Domain.Entity;
using TR.Domain.Repository.Bs_SupplyRepository;

namespace TR.AppService.AppService.Bs_Supply
{
    public class bs_SupplyAppService : Ibs_SupplyAppService
    {
        private readonly Ibs_SupplyRepository Bsr;//Domain中的接口
        private readonly IMapper mapper;

        //初始化
        public bs_SupplyAppService(Ibs_SupplyRepository Bsr,IMapper mapper)
        {
            this.Bsr = Bsr;
            this.mapper = mapper;
        }
        public async Task<DtoFenYe<bs_Supply>> FenYeSupply(int pagesize , int currentpage, SupplyFenyeTjDto sft)
        {
            bs_Supply bsy = mapper.Map<bs_Supply>(sft);
            var listFenYe = await Bsr.SupplyFenYeTjAsync(pagesize,currentpage, bsy);
            var fyzts = await Bsr.ZtsSelectAsync();

            var res = new DtoFenYe<bs_Supply>()
            {
                dqy = currentpage,
                mys = pagesize,
                list = listFenYe,
                zts = fyzts,
            };

            return res;
        }

        public async Task<bool> SupplyAdd(SupplyDtoAdd supplyDtoAdd)
        {
            bs_Supply bs_Supply = mapper.Map<bs_Supply>(supplyDtoAdd);
            return await Bsr.SupplyAddAsync(bs_Supply);
        }

        public async Task<bool> SupplyAddFinance(FinanceAdd financeAdd)
        {
            bs_Finance bs_Finance = mapper.Map<bs_Finance>(financeAdd);
            return await Bsr.FinanceAddAsync(bs_Finance);
        }
    }
}
